// pages/find/search.js
const app = getApp()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        list: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.setData(options)
    },
    onInput(e) {
        this.setData({
            content: e.detail.value,
            page:0,
            loading:false,
            list:[],
            nextFlag:true
        })
    },
    onShow(){
       
    },
    search() {
        if (!this.data.content) {
            wx.showToast({
                title: '请输入搜索内容~',
                icon: 'none'
            })
            return
        }
        let {
            page = 0,
                loading = false,
                list = [],
                nextFlag = true
        } = this.data
        if (loading || !nextFlag) {
            return
        }
        this.setData({
            loading: true
        })
        app.http.get("city/msg/get-all-article?page=" + page + '&word=' + this.data.content).then(res => {
            console.log(page, 'page')
            page++
            loading = false
            list.push(...res.data.data)
            for (var i = 0; i < list.length; i++) {
                list[i].images = list[i].msg_content.find(o => {
                    return !!o.images
                })
            }
            nextFlag = res.data.nextFlag
            this.setData({
                page,
                loading,
                list,
                nextFlag
            })
        })
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        this.search()
    }
})